package com.manman;

import androidx.appcompat.app.AppCompatActivity;
import androidx.fragment.app.Fragment;
import androidx.viewpager.widget.ViewPager;

import android.os.Bundle;
import android.view.View;

import com.google.android.material.tabs.TabLayout;
import com.manman.adapter.RecordPagerAdapter;
import com.manman.fragment.IncomeFragment;
import com.manman.fragment.OutcomeFragment;

import java.util.ArrayList;
import java.util.List;

public class RecordActivity extends AppCompatActivity {

    TabLayout tablayout;
    ViewPager viewPager;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_record);

        //1.查找控件
        tablayout = findViewById(R.id.record_tabs);
        viewPager = findViewById(R.id.record_vp);

        //2.设置Viewpage加载页面
        initPager();
    }

    private void initPager() {
        //初始化Viewpage页面
        List<Fragment> fragmentList = new ArrayList<>();
        //创建收入支出页面，放置在fragment中
        OutcomeFragment outcomeFragment = new OutcomeFragment();
        IncomeFragment incomeFragment = new IncomeFragment();

        fragmentList.add(outcomeFragment);
        fragmentList.add(incomeFragment);

        //创建适配器
        RecordPagerAdapter recordPagerAdapter = new RecordPagerAdapter(getSupportFragmentManager(), fragmentList);
        //设置适配器
        viewPager.setAdapter(recordPagerAdapter);

        //将TabLayout 和 Viewpage 进行关联
        tablayout.setupWithViewPager(viewPager);

    }

    /*点击事件*/
    public void onclick(View view) {
        switch (view.getId()) {
            case R.id.record_iv_back:
                finish();
                break;
        }
    }
}